﻿/// <reference path="jquery/jquery-1.9.1.js" />
$(function () {

    //var format = '<tr id="post-{id}" class="status-{status}">' +
    //                        '<th class="check-column">' +
    //                            '<label class="screen-reader-text" for="select-{id}">选择</label>' +
    //                            '<input id="select-{id}" class="ck-select" type="checkbox">' +
    //                        '</th>' +
    //                        '<td class="title">' +
    //                            '<strong><a class="row-title" href="#" title="编辑《{title}》">{title}</a></strong>' +
    //                            '<div class="row-actions">' +
    //                                '<span class="edit"><a href="#" title="编辑此项目">编辑</a> | </span>' +
    //                                '<span class="inline"><a href="#" class="editinline" title="实时编辑此项目">快速编辑</a> | </span>' +
    //                                '<span class="trash"><a class="submitdelete" title="移动此项目到回收站" href="#">移至回收站</a> | </span>' +
    //                                '<span class="view"><a href="#" title="查看《{title}》”" rel="permalink">查看</a></span>' +
    //                            '</div>' +
    //                        '</td>' +
    //                        '<td class="author column-author"><a href="{author_url}">{author}</a></td>' +
    //                        '<td class="categories column-categories">{categories}</td>' +
    //                        '<td class="tags column-tags">{tags}</td>' +
    //                        '<td class="comments column-comments">' +
    //                            '<div class="post-com-count-wrapper">' +
    //                                '<a href="#" title="{awaiting-count} 待审中" class="post-com-count"><span class="comment-count">{comment-count}</span></a>' +
    //                            '</div>' +
    //                        '</td>' +
    //                        '+<td class="date column-date">' +
    //                            '+<abbr title="{date}">{date}</abbr><br/>{status}</td>' +
    //                    '+</tr>';
    var format = '<tr id="post-{id}" class="type-post status-publish">' +
                                '<th scope="row" class="check-column">' +
                                    '<label class="screen-reader-text" for="cb-select-{id}">选择 {title}</label>' +
                                    '<input id="cb-select-{id}" type="checkbox" name="post[]" value="{id}" />' +
                                '</th>' +
                                '<td class="post-title page-title column-title"><strong><a class="row-title" href="?post={id}&amp;action=edit" title="编辑“{title}”">{title}</a></strong>' +
                                    '<div class="row-actions"><span class="edit"><a href="?post={id}&amp;action=edit" title="编辑此项目">编辑</a> | </span><span class="inline"><a href="#" class="editinline" title="实时编辑此项目">快速编辑</a> | </span><span class="trash"><a class="submitdelete" title="移动此项目到回收站" href="?post={id}&amp;action=trash&amp;_wpnonce=66b4cb2492">移至回收站</a> | </span><span class="view"><a href="#" title="查看“{title}”" rel="permalink">查看</a></span></div>' +
                                '</td>' +
                                '<td class="author column-author">{author}</td>' +
                                '<td class="categories column-categories">{categories}</td>' +
                                '<td class="tags column-tags">{tags}</td>' +
                                '<td class="comments column-comments">' +
                                    '<div class="post-com-count-wrapper">' +
                                        '<a href="edit-comments.php?p={id}" title="{comment-count} 条评论" class="post-com-count"><span class="comment-count">{comment-count}</span></a>' +
                                    '</div>' +
                                '</td>' +
                                '<td class="date column-date">' +
                                    '<abbr title="{date}">{date}</abbr><br />{status}' +
                                    '</td>' +
                            '</tr>';
    $.getJSON('handler/post-ajax.ashx', { action: 'loadpostlist', page: 1, rows: 20 }, function (data) {
        var posts=data.rows;
        for (var i = 0; i < posts.length; i++) {
            //console.log();
            $('#the-list').append(format.replace(/{id}/g, posts[i].Id).replace(/{title}/g, posts[i].Title).replace(/{author}/g, posts[i].Author).replace(/{categories}/g, posts[i].Category).replace(/{tags}/g, posts[i].Tag).replace(/{comment-count}/g, posts[i].CommentCount).replace(/{date}/g, posts[i].PubDate).replace(/{status}/g, posts[i].Status));
        }
        $('#the-list tr:even').addClass('alternate');
    })
});